// pages/store/storedetail/detail.js

import { PNT, setNavBarTitle, showToast, uniqueArray, pushPagePath } from "../../../utils/utils";
import { GetShopDetail, AddAttention, CheckAttention } from "../../../utils/apis";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    logo:'http://donglongshangshi.oss-cn-beijing.aliyuncs.com/seller_imgs/seller_logo/logo_thumb/1490159042082423990.jpg',
    title:'万卓旗舰店',
    people:200,
    gz:1,
    sp:5,
    fw:4,
    sx:3,
    num1:20,
    num2:10,
    num3:0,
    address:'中山北路3553号中山北路3553号',
    brand:'网做多多多多',
    level:'普通商家',
    callGetPhone: '1823516028',
    attention: 0,
  },
// 二维码
  //打开二维码
  showRule: function () {
    this.setData({
      isRuleTrue: true
    })
  },

  //关闭二维码提示
  hideRule: function () {
    this.setData({
      isRuleTrue: false
    })
  },
  // 拨打电话给商家
    callGetPhone(e) {
  // 号码
   let telPhone = e.currentTarget.dataset.getphone;
    this.callPhone(telPhone);
},

  /**
   * 拨打电话 - 可简单封装工具集
   */
  callPhone(phoneNumber) {
   wx.makePhoneCall({
    phoneNumber: phoneNumber,
    success: function() {
      console.log("拨打电话成功！")
      
      },
      fail: function() {
        console.log("拨打电话失败！")
      
      }
   })
   },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let ru_id = options.ru_id || 0;
    setNavBarTitle(PNT.goods.detail);
    this.loginModal = this.selectComponent("#login-modal");
    if (!ru_id) {
      showToast('数据异常', 'warning');
      setTimeout(() => {
        wx.navigateBack({
          delta: 1,
        })
      }, 2000)
      return;
    }
    this.setData({
      ru_id: ru_id,
    })
    this.getShopInfo();
    this.checkAttention();

  },
  getShopInfo() {
    let data = {};
    let that = this;
    data.ru_id = this.data.ru_id;
    data.page = this.data.page;
    GetShopDetail(data).then(res => {
      if (res.error_code == 10000) {


          this.setData({
            info: res.data
          })
        
      } else {
        showToast(res.msg, 'warning');
      }
    })
  },
  checkAttention() {
    var data = {};
    data.ru_id = this.data.ru_id;
    if (!this.loginModal.check()) {
      return false;
    }
    var info = wx.getStorageSync('userInfo');
    data.user_id = info.user_id;
    CheckAttention(data).then(res => {
      if (res.error_code == 10000) {
        this.setData({
          attention: res.data
        })
      } else {
        showToast(res.msg, 'warning')
      }
    })
  },
  addAttention() {
    var data = {};
    data.ru_id = this.data.ru_id;
    if (!this.loginModal.check()) {
      return false;
    }
    var info = wx.getStorageSync('userInfo');
    data.user_id = info.user_id;
    AddAttention(data).then(res => {
      if (res.error_code == 10000) {
        this.setData({
          attention: res.data
        })
      } else {
        showToast(res.msg, 'warning')
      }
    })
  },

/**
* 页面跳转
* @author darlang
*/
  pushPath(e) {
    const items = e.currentTarget.dataset;
    const pathData = [
      { type: 'cat', path: '/pages/goods/list/list?catId=' + items.id + "&ru_id=" + this.data.ru_id },
      { type: 'all', path: '/pages/goods/list/list?ru_id=' + this.data.ru_id },
      { type: 'new', path: '/pages/goods/list/list?is_new=1&ru_id=' + this.data.ru_id },
      { type: 'promote', path: '/pages/goods/list/list?is_promote=1&ru_id=' + this.data.ru_id },
      { type: 'search', path: '/pages/goods/list/list?ru_id=' + this.data.ru_id },
    ];
    pushPagePath(e, pathData);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})